package com.yanqu.road.server.cmd.unioncampwar.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.unionCampWar.UnionCampWar;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.unioncampwar.UnionCampWarPatronsMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;


@Cmd(code = GameProtocol.S_UNION_CAMP_WAR_PATRONS_NUM_CROSS_REQ, desc = "商会跨服请求门客数")
public class CrossUnionCampPatronsNumReqCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        UnionCampWar.CrossUnionCampWarPatronsNumReqMsg reqMsg = UnionCampWar.CrossUnionCampWarPatronsNumReqMsg.parseFrom(packet.getBytes());
        UnionCampWar.CrossUnionCampWarPatronsNumRespMsg.Builder respMsg = UnionCampWar.CrossUnionCampWarPatronsNumRespMsg.newBuilder();
        respMsg.setCenterGroupId(reqMsg.getCenterGroupId());
        respMsg.setGroupId(reqMsg.getGroupId());
        respMsg.setUnionId(reqMsg.getUnionId());
        int patronsNum = UnionCampWarPatronsMgr.getUnionAllPatronsNum(reqMsg.getUnionId(), reqMsg.getMemberIdList());
        if (patronsNum > 0) {
            respMsg.setPatronsNum(patronsNum);
            GamePlayerMgr.sendPacket(0, YanQuMessageUtils.buildMessage(CrossProtocol.C3_UNION_CAMP_WAR_PATRONS_NUM_BACK, respMsg));
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (null == player) {
            return;
        }
    }
}
